/**GPIO_Mode
	1. **GPIO_Mode_AIN = 0x0**：AIN应该是模拟输入（Analog IN），用于ADC或其他模拟信号读取。这时候GPIO作为模拟输入，不进行数字信号的处理。

	2. **GPIO_Mode_IN_FLOATING = 0x04**：输入浮空模式。浮空输入模式下，GPIO处于高阻抗状态，没有内部上拉或下拉电阻。适用于需要外部电路提供电平的情况，比如接按键时需要外接上拉或下拉电阻。

	3. **GPIO_Mode_IPD = 0x28**：输入下拉（Input Pull-Down）。内部下拉电阻被启用，输入默认被拉低，当外部无信号时，引脚电平为低。

	4. **GPIO_Mode_IPU = 0x48**：输入上拉（Input Pull-Up）。内部上拉电阻被启用，输入默认被拉高，外部无信号时引脚为高电平。

	5. **GPIO_Mode_Out_OD = 0x14**：开漏输出（Open-Drain Output）。输出模式下，开漏结构允许引脚在输出低电平时导通到地，高电平时则处于高阻态，需要外部上拉电阻才能输出高电平。适用于总线配置，如I2C。

	6. **GPIO_Mode_Out_PP = 0x10**：推挽输出（Push-Pull Output）。推挽结构可以主动输出高或低电平，驱动能力强，适用于需要高低电平驱动的场合，如控制LED。

	7. **GPIO_Mode_AF_OD = 0x1C**：复用功能开漏（Alternate Function Open-Drain）。当GPIO被配置为外设功能（如I2C的SCL/SDA）时使用开漏模式，同样需要外部上拉。

	8. **GPIO_Mode_AF_PP = 0x18**：复用功能推挽（Alternate Function Push-Pull）。外设功能使用推挽输出，如SPI的时钟或MOSI线。

	典型应用场景
	按键检测：

	浮空输入 + 外部上拉电阻（GPIO_Mode_IN_FLOATING）

	或直接使用内部上拉（GPIO_Mode_IPU）

	LED 控制：

	推挽输出（GPIO_Mode_Out_PP），直接驱动 LED

	I2C 通信：

	复用开漏模式（GPIO_Mode_AF_OD），需外接上拉电阻

	ADC 采样：

	模拟输入模式（GPIO_Mode_AIN），关闭数字干扰
**/
/**通过调用库函数来实现IO控制的方法*****************************************
int main(void){ 
	delay_init();//初始化延时函数
	LED_Init();//初始化LED端口
	while(1){
		GPIO_ResetBits(GPIOB,GPIO_Pin_5);  //LED0对应引脚GPIOB.5拉低，亮  等同LED0=0;
		GPIO_SetBits(GPIOE,GPIO_Pin_5);   //LED1对应引脚GPIOE.5拉高，灭 等同LED1=1;
		delay_ms(300);//延时300ms
		GPIO_SetBits(GPIOB,GPIO_Pin_5);	   //LED0对应引脚GPIOB.5拉高，灭  等同LED0=1;
		GPIO_ResetBits(GPIOE,GPIO_Pin_5); //LED1对应引脚GPIOE.5拉低，亮 等同LED1=0;
		delay_ms(300);                     //延时300ms
	}
} 
**/	
/**通过 直接操作寄存器 方式实现IO口控制**************************************
int main(void){ 
	delay_init();//初始化延时函数
	LED_Init();//初始化LED端口
	while(1){
		GPIOB->BRR=GPIO_Pin_5;//LED0亮
		GPIOE->BSRR=GPIO_Pin_5;//LED1灭
		delay_ms(300);
		GPIOB->BSRR=GPIO_Pin_5;//LED0灭
		GPIOE->BRR=GPIO_Pin_5;//LED1亮
		delay_ms(300);
	}
}
**/

#include "HX711.h"
#include "MyFunction.h"
#define mode_ain_gpios_len 84
void gpiosInitToMode_AIN(void){
	u8 i=0;
	char para[6] = {0};
	char *gpios[mode_ain_gpios_len] = {
"A2","A3","A4","A5","A6","A7","A8",
"B6","B7","B8","B9","B10","B11",
"C0","C1","C2","C3","C4","C5","C6","C7","C8","C9","C10","C11","C12",
"D0","D1","D2","D3","D4","D5","D6","D7","D8","D9","D10","D11","D12","D13","D14","D14",
"E0","E1","E2","E6","E7","E8","E9","E10","E11","E12","E13","E14","E15",
"F0","F1","F2","F3","F4","F5","F6","F7","F11","F12","F13","F14","F15",
"G0","G1","G2","G3","G4","G5","G6","G7","G8","G9","G10","G11","G12","G13","G14","G15"};
	printf("gpiosInitToMode_AIN");
	for(;i<mode_ain_gpios_len;i++){
		snprintf(para,6,"%s|%d",gpios[i],0);//0为gpio_mode_cb[8]索引对应GPIO_Mode_AIN
		printf("%s",para);
		gpioInit(para);
	}
}
void sendOpsCodeToWebServer(void){
	printf("gpioInit|%d,gpioOutHigh|%d,gpioOutlow|%d,delayMs|%d,IRQconfig|%d,hx711JiaoZhun|%d,hx711Config|%d,hx711GetWeight|%d,waitForInterrupt|%d,delayS|%d,enableInterrupt|%d",
	gpioInit,
	gpioOutHigh,
	gpioOutlow,
	delayMs,
	IRQconfig,
	hx711JiaoZhun,
	hx711Config,
	hx711GetWeight,
	waitForInterrupt,
	delayS,
	enableInterrupt
	);
}

int main(void){
	 func_ptr fp = NULL;
	 unsigned int num_fp;
	 char *endptr_fp;//用于strtol函数调用后检查错误 if (endptr_fp == queue_a[queue_handling_i].c) {// 无有效数字//} else if (*endptr != '\0') {// 字符串含非数字字符（例如"abc"）//}
	 char *temp,*next_p,*temp_next_p;
	 //SystemInit();
	 //rtcInit();  	 
	 delay_init();
	 uartInit(115200);
	 gpiosInitToMode_AIN();//初始化所有可用的引脚为模拟输入，旨为安全，可靠，低功耗。
	 __enable_irq(); // 启用全局中断
	 printf("sendOpsCodeToWebServer %d",sendOpsCodeToWebServer);
	while(1){//q_readable_count可读队员数不为0
    if(Q_LEN == q_search_readable_i)q_search_readable_i = 0;//最后队号不可读时，从头开始寻找可读队员，如此往复
    if(QUEUE_STATUS_WRITABLE == queue_a[q_search_readable_i].s){q_search_readable_i++;continue;}//跳过可写队员
      printf("q_readable_count %d Start processing queue_a[%d] %s\r\n",q_readable_count,q_search_readable_i,queue_a[q_search_readable_i].c);
      next_p = queue_a[q_search_readable_i].c;
      while(*next_p){
        temp = myStrsep(next_p, "_",&next_p);
        num_fp = strtol(myStrsep(temp,"|",&temp_next_p), &endptr_fp, 10);
        fp = (func_ptr)num_fp;
        fp(temp_next_p);// 执行函数
      }
      //printf("ops_queueb[%d] processing completed",q_search_readable_i);
    queue_a[q_search_readable_i].s = QUEUE_STATUS_WRITABLE;
    q_search_readable_i++;
    q_readable_count--;
	}
}


